package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.SeekBar;

import com.hpplay.sdk.source.api.LelinkPlayerInfo;
import com.hpplay.sdk.source.api.LelinkSourceSDK;
import com.stark.cast.screen.CastScreenManager;

import java.io.IOException;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.databinding.ActivityProAudioBinding;
import stark.common.basic.utils.MediaUtil;
import stark.common.basic.utils.TimeUtil;
import stark.common.basic.utils.UriUtil;

public class ProAudioActivity extends BaseAc<ActivityProAudioBinding> {

    public static String audioPath="";
    private CastScreenManager mCastScreenManager;
    private MediaPlayer mediaPlayer = new MediaPlayer();


    @Override
    protected int onCreate() {
        return R.layout.activity_pro_audio;
    }

    @Override
    protected void initView() {
        mDataBinding.ivProAudioBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        mCastScreenManager = CastScreenManager.getInstance();
    }

    @Override
    protected void initData() {
        if (audioPath.isEmpty()) return;
        proMusic(audioPath);
        try {
            mediaPlayer.setDataSource(audioPath);
            mediaPlayer.prepare();
            //直接播放音频
            mediaPlayer.start();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    //音乐投屏
    private void proMusic(String url) {
        LelinkPlayerInfo playerInfo = new LelinkPlayerInfo();
        playerInfo.setType(LelinkSourceSDK.MEDIA_TYPE_AUDIO);
        Uri uri = Uri.parse(url);
        if (UriUtil.isContentSchemeUri(uri)) {
            playerInfo.setLocalUri(uri);
        } else {
            playerInfo.setLocalPath(url);
        }
        mCastScreenManager.startPlay(playerInfo);
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (mediaPlayer != null) {
            mediaPlayer.stop();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mediaPlayer != null) {
            mediaPlayer.stop();
            mediaPlayer.release();
        }
    }

}